# Maintainer: Sergej Pupykin <pupykin.s@gmail.com>
# Contributor: damir <damir@archlinux.org>

pkgname=libextractor
pkgver=1.11
pkgrel=6
pkgdesc="A library used to extract meta-data from files of arbitrary type"
arch=("loong64" "x86_64")
license=('GPL')
url="https://www.gnu.org/software/libextractor/"
depends=('libltdl')
makedepends=('exiv2' 'ffmpeg' 'file' 'flac' 'gst-plugins-base-libs' 'libgsf' 'libmpeg2' 'libvorbis'
             'poppler' 'libsmf')
optdepends=('exiv2: metadata support'
            'ffmpeg: previewopus/thumbnailffmpeg support'
            'file: mime support'
            'flac: flac support'
            'gst-plugins-base-libs: gstreamer support'
            'libarchive: archive support'
            'libgsf: (optional) for ODF support'
            'libmpeg2: mpeg support'
            'libvorbis: ogg/vorbis support'
            'poppler: pdf support'
            'libsmf: midi support')
validpgpkeys=('19647543F7861D3BF4E64FF7BF60708B48426C7E'
              'D8423BCB326C7907033929C7939E6BE1E29FC3CC')
source=("https://ftp.gnu.org/gnu/libextractor/${pkgname}-${pkgver}.tar.gz"{,.sig}
         ffmpeg5.patch
         exiv2-0.28.patch)
sha512sums=('7023d8cb377fda854523242ac9fd14a97eed86d2cd829b126bb4d5a26d5f3650642f3871cf74ae3b0788447cc0a2dce942684ef0d45f17c9ba9248b5aed623d3'
            'SKIP'
            'c81ef943428729f1edaad9a928cfff982e635c2990232cc407b8982f4d2b1925bf5aed28077151c96a3868733d7022fa0d0097927bf6f9cff91c6c47e3eae67a'
            '5ea7d0673b2dfa71ad7e87afad4753d55e5535953a4e53b2d37430c906f1c3e68ac306dab3ca1469e840038396c8537848d865447111156d575b9dba3a5085a2')

prepare() {
  cd $pkgname-$pkgver
  sed -e 's/ CODEC_FLAG_QSCALE/ AV_CODEC_FLAG_QSCALE/' \
      -e 's/FF_INPUT_BUFFER_PADDING_SIZE/AV_INPUT_BUFFER_PADDING_SIZE/' \
      -i src/plugins/thumbnailffmpeg_extractor.c
  patch -p1 -i ../ffmpeg5.patch # Fix build with FFmpeg 5
  patch -p1 -i ../exiv2-0.28.patch # Fix build with exiv2 0.28
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --enable-shared --disable-static
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  rm "$pkgdir"/usr/share/info/dir
}
